import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutterdemo/0demo/appbar_tab_bar/appbar_tab_bar.dart';

void main() {
  testWidgets("app bar test", (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: AppbarTabBarPage(),
    ));
    expect(find.text('CAR'), findsNWidgets(2));
    expect(find.text('BOAT'), findsNWidgets(1));

    // 这里注意是向左滑动，所以偏移量为负
    await tester.drag(find.byType(TabBarView), Offset(-1000, 0));
    await tester.pumpAndSettle();
    // await tester.pump(Duration(milliseconds: 3000));
    expect(find.text('CAR'), findsNWidgets(1));
    expect(find.text('BICYCLE'), findsNWidgets(2));

    // tab index is 2
    // 向右拖动，回到第一页
    await tester.drag(find.byType(TabBarView), Offset(1000, 0));
    await tester.pumpAndSettle();
    expect(find.text('CAR'), findsNWidgets(2));
    expect(find.text('BICYCLE'), findsNWidgets(1));

    // test index == 3 case.
    await tester.drag(find.byType(TabBarView), Offset(-1000, 0));
    await tester.drag(find.byType(TabBarView), Offset(-1000, 0));
    await tester.pumpAndSettle();
    expect(find.text('BOAT'), findsNWidgets(2));
    expect(find.text('BICYCLE'), findsNWidgets(1));
  });
}
